<?php
namespace core;

use core\View;
use core\Request;
use core\Response;

class Controller
{
    // 视图实例
    protected $view;

    public function __construct(){
        $this->view = new View();
        $this->request = new Request();
        $this->response = new Response();
    }

    // 获取请求参数（GET/POST）
    protected function param($key = null, $defult = null){
        if($key === null){
            return array_merge($_GET, $_POST);
        }
        return $_REQUEST[$key] ?? $defult;
    }

    // 渲染视图（由子类调用）
    protected function fetch($template, $data = []){
        return $this->view->render($template, $data);
    }

    // 快速返回 JSON 响应
    // protected function json($data = [], $code = 200) {
    //     http_response_code($code);
    //     header('Content-Type: application/json');
    //     echo json_encode($data);
    //     exit;
    // }
}